﻿using Furion.DatabaseAccessor;
using Furion.DataEncryption;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;

namespace Mrhd.Core.Entities
{
    /// <summary>
    /// 用户表
    /// </summary>
    [Table("Sys_User")]
    [Comment("用户表")]
    public class UserEntity : Entity, IEntitySeedData<UserEntity>, IEntityTypeBuilder<UserEntity>
    {
        /// <summary>
        /// 登录名
        /// </summary>
        [Comment("登录名")]
        [MaxLength(64)]
        [Required]
        public string UserName { get; set; }
        /// <summary>
        /// 邮箱
        /// </summary>
        [Comment("邮箱")]
        [MaxLength(64)]
        public string Email { get; set; }
        /// <summary>
        /// 密码
        /// </summary>
        [Comment("密码")]
        [MaxLength(64)]
        public string Password { get; set; }
        /// <summary>
        /// 手机号
        /// </summary>
        [Comment("手机号")]
        [MaxLength(64)]
        public string Phone { get; set; }
        /// <summary>
        /// 用户全名
        /// </summary>
        [Comment("用户全名")]
        [MaxLength(32)]
        public string FullName { get; set; }
        /// <summary>
        /// 年龄
        /// </summary>
        [Comment("年龄")]
        public int Age { get; set; }
        /// <summary>
        /// 性别
        /// </summary>
        [Comment("性别")]
        public GenderType Gender { get; set; }
        /// <summary>
        /// 头像地址
        /// </summary>
        [Comment("头像地址")]
        [MaxLength(512)]
        public string Avator { get; set; }
        /// <summary>
        /// 是否激活
        /// </summary>
        [Comment("是否激活")]
        public bool IsActive { get; set; }
        /// <summary>
        /// 是否是管理员
        /// </summary>
        [Comment("是否是管理员")]
        public bool IsAdmin { get; set; }
        /// <summary>
        /// 最后登录时间
        /// </summary>
        [Comment("最后登录时间")]
        public DateTimeOffset? LastLoginTime { get; set; }
        /// <summary>
        /// 员工编码
        /// </summary>
        [Comment("员工编码")]
        [MaxLength(32)]
        public string Code { get; set; }
        /// <summary>
        /// 地址列表
        /// </summary>
        public virtual ICollection<AddressEntity> Addresses { get; set; }
        /// <summary>
        /// 可访问的路由
        /// </summary>
        public virtual ICollection<AccessAuthorityEntity> AccessAuthorities { get; set; }

        /// <summary>
        /// Fluent Api
        /// </summary>
        /// <param name="entityBuilder"></param>
        /// <param name="dbContext"></param>
        /// <param name="dbContextLocator"></param>
        public void Configure(EntityTypeBuilder<UserEntity> entityBuilder, DbContext dbContext, Type dbContextLocator)
        {

        }

        /// <summary>
        /// 种子
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="dbContextLocator"></param>
        /// <returns></returns>
        public IEnumerable<UserEntity> HasData(DbContext dbContext, Type dbContextLocator)
        {
            var time = new DateTimeOffset(2021, 9, 21, 8, 0, 0, default);
            return new List<UserEntity>
            {
                new UserEntity{ Id = 1, UserName = "sunxsh", Age = 33, Code = "10000001", CreatedTime = time, Email = "281267775@qq.com", FullName = "孙小双", Gender = GenderType.Male, IsAdmin = true, IsActive = true, Password = MD5Encryption.Encrypt("000000"), Phone = "17354300837" },
                new UserEntity{ Id = 2, UserName = "liyr", Age = 32, Code = "10000002", CreatedTime = time.AddMonths(1), Email = "345521556@qq.com", FullName = "李怡然", Gender = GenderType.Female, IsAdmin = false, IsActive = true, Password = MD5Encryption.Encrypt("000000"), Phone = "18955412235" },
                new UserEntity{ Id = 3, UserName = "admin", Age = 27, Code = "10000003", CreatedTime = time.AddMonths(2), Email = "558521145@qq.com", FullName = "管理员", Gender = GenderType.None, IsAdmin = true, IsActive = true, Password = MD5Encryption.Encrypt("000000"), Phone = "13971962638" }
            };
        }
    }

}
